import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
import { ProductService } from './product.service';
import { CreateProductDto, QueryProductDto, UpdateProductDto } from './dto/shop-product.dto';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';

@Controller('shop/product')
export class ProductController {
  constructor(private readonly productService: ProductService) {}
  @RequirePermission('shop:product:list')
  @Get()
  list(@Query() data: QueryProductDto) {
    return this.productService.findList(data);
  }

  @Get('list')
  findAll(@Query() data: QueryProductDto) {
    return this.productService.findAll(data.name);
  }

  @RequirePermission('shop:product:add')
  @Post()
  create(@Body() data: CreateProductDto) {
    return this.productService.create(data);
  }

  @RequirePermission('shop:product:findOne')
  @Get(':id')
  findOne(@Param('id') id: number) {
    return this.productService.findOne(id);
  }

  @RequirePermission('shop:product:update')
  @Put()
  update(@Body() data: UpdateProductDto) {
    return this.productService.update(data);
  }
  @RequirePermission('shop:product:delete')
  @Delete(':id')
  remove(@Param('id') id: number) {
    return this.productService.remove(id);
  }
}
